const app = getApp();
// pages/set/set.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    theme: "",
    changeTheme: false,
    themeType: app.globalData.themeType,
    hide: false
  },

  goPage(e) {
    const { page } = e.currentTarget.dataset;
    switch (page) {
      case "theme":
        wx.showToast({
          title: "开发中",
          icon: "none",
        });
        // wx.navigateTo({
        //   url: '/packageMore/pages/theme/theme',
        // })
        break;
      case "music":
        if (this.data.hide) {
          wx.navigateTo({
            url: "/packageMore/pages/music/music",
          });
        } else {
          wx.navigateTo({
            url: "/packageMore/pages/music/index/index",
          });
        }
        break;
      case "music1":
        wx.navigateTo({
          url: "/packageMore/pages/music/music",
        });
        break;
      case "element":
        wx.navigateTo({
          url: "/packageMore/pages/tools/tools",
        });
        break;
      case "turntable":
        wx.navigateTo({
          url: "/packageMore/pages/turntable/turntable",
        });
        break;
      case "module":
        wx.navigateTo({
          url: "/packageElement/pages/index/index",
        });
        break;
      case "function":
        wx.navigateTo({
          url: "/packageFunction/pages/index/index",
        });
        break;
      case "picture":
        wx.navigateTo({
          url: "/packageMore/pages/picture/picture",
        });
        break;
      default:
        break;
    }
  },

  onChange(e) {
    const detail = e.detail;
    if (detail.value) {
      this.setTheme("dark");
    } else {
      this.setTheme("default");
    }
    this.setData({
      changeTheme: detail.value,
    });
  },

  setTheme(theme) {
    wx.setStorageSync("themeType", theme);
    app.globalData.themeType = theme;
    if (theme == "dark") {
      wx.setNavigationBarColor({
        backgroundColor: "#121212",
        frontColor: "#ffffff",
      });
      wx.setBackgroundColor({
        backgroundColor: '#181818', // 窗口的背景色
        backgroundColorTop: '#181818', // 顶部窗口的背景色
        backgroundColorBottom: '#181818', // 底部窗口的背景色
      })
    } else {
      wx.setNavigationBarColor({
        backgroundColor: "#ffffff",
        frontColor: "#000000",
      });
      wx.setBackgroundColor({
        backgroundColor: '#ffffff', // 窗口的背景色
        backgroundColorTop: '#ffffff', // 顶部窗口的背景色
        backgroundColorBottom: '#ffffff', // 底部窗口的背景色
      })
    }
    this.setData({
      themeType: theme,
    });
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        themeType: theme,
      });
    }
  },

  openMiniProgram(e) {
    const { program } = e.currentTarget.dataset;
    console.log(program);
    switch (program) {
      case "loveZone":
        wx.openEmbeddedMiniProgram({
          appId: "wx9a44ab6c8170142c",
        });
        break;
      case "shop":
        wx.openEmbeddedMiniProgram({
          appId: "wx3a17e3521377c02e",
        });
        break;
      case "order":
        wx.openEmbeddedMiniProgram({
          appId: "wx5af8bbf6b146bddb",
        });
        break;

      default:
        break;
    }
  },

  callme() {
    wx.makePhoneCall({
      phoneNumber: "19293590927",
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 3,
        themeType: app.globalData.themeType,
      });
    }

    const hide = app.globalData.hide;
    this.setData({
      hide
    })

    const themeType = wx.getStorageSync("themeType");
    if (themeType == "dark") {
      this.setData({
        changeTheme: true,
      });
      wx.setNavigationBarColor({
        backgroundColor: "#121212",
        frontColor: "#ffffff",
      });
      wx.setBackgroundColor({
        backgroundColor: '#181818', // 窗口的背景色
        backgroundColorTop: '#181818', // 顶部窗口的背景色
        backgroundColorBottom: '#181818', // 底部窗口的背景色
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },
});
